package com.sc.nft.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.OrderDTO;
import com.sc.nft.entity.Order;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.dto.FlowRecordDTO;
import com.sc.nft.entity.dto.OrderFirstPayDTO;
import com.sc.nft.entity.dto.OrderRushPayDTO;
import com.sc.nft.entity.vo.*;
import com.sc.nft.enums.ClassifyType;
import com.sc.nft.enums.OrderStatusEnum;
import com.sc.nft.enums.PayMethodEnum;
import com.sc.nft.exception.GlobalException;
import com.sc.nft.sup.Result;

import java.util.Date;
import java.util.List;

/**
 * 订单表服务接口
 *
 * @author zxy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-06-02 01:04:25
 */
public interface OrderService {

    /**
     * 创建订单
     *
     * @param productId
     * @return
     */
    CreateOrderVO createOrder(Long productId, Integer count, List<OrderFirstPayDTO> firstPayDTO, List<OrderRushPayDTO> rushBuyDTOs) throws GlobalException;

    /**
     * 创建原石订单
     *
     * @param userInfo
     * @param productId
     * @param count
     * @return
     * @throws GlobalException
     */
    CreateOrderVO createRoughStoneOrder(UserInfo userInfo, Long productId, Integer count) throws GlobalException;

    /**
     * 关闭订单
     *
     * @param id
     * @throws GlobalException
     */
    void closeOrder(Long id) throws GlobalException;

    /**
     * 订单列表
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    IPage orderPage(OrderStatusEnum orderStatus, ClassifyType orderType, int pageNo, int pageSize);

    /**
     * 自动关闭订单
     *
     * @param order
     * @throws GlobalException
     */
    void autoCloseOrder(Order order) throws GlobalException;

    /**
     * 获取自动关闭订单
     *
     * @return
     */
    List<Order> getCloseOrder();

    void paySuccess(String orderNo) ;

    /**
     * 获取支付签名
     *
     * @param orderId
     * @return
     */
    GetPaySignVO getPaySign(Long orderId, PayMethodEnum payMethodEnum) throws GlobalException;


    /**
     * 根据交易流水号查询支付状态
     *
     * @param orderNo
     */
    Result getAliPayStatusByOrderNo(String orderNo);

    /**
     * 根据订单号查询订单信息
     *
     * @param orderNo
     * @return
     */
    CreateOrderVO findOrderByOrderNo(String orderNo);

    /**
     * 后台订单列表
     *
     * @param phone
     * @param orderNo
     * @param productUuId
     * @param status
     * @param startOrderTime
     * @param endOrderTime
     * @param startPayTime
     * @param endPayTime
     * @param pageNo
     * @param pageSize
     * @return
     */
    Page<OrderDTO> orderPageForAdmin(String firstTitle, String phone, String orderNo, String productUuId, OrderStatusEnum status, Date startOrderTime, Date endOrderTime, Date startPayTime, Date endPayTime, int pageNo, int pageSize);

    /**
     * 订单导出
     *
     * @param productId
     * @return
     */
    List<OrderSimpleVO> orderExport(Long productId);

    /**
     * 订单明细导出
     *
     * @param productId
     * @return
     */
    List<OrderDetailListVO> orderDetailExport(Long productId, Date payTimeFrom, Date payTimeTo);

    /**
     * 获取订单详情
     *
     * @param id
     * @return
     */
    OrderDetailsVO getOrderDetailsById(Long id);

    /**
     * 查询是否支付成功
     *
     * @param orderNo
     * @return
     */
    Boolean getOrderStatus(String orderNo);

    /**
     * 获取折扣后的价格
     *
     * @param productId
     * @param productCount
     * @return
     */
    GetTotalPriceVO getTotalPrice(Long productId, String productCount);

    /**
     * @param start   起始条目
     * @param end     结束条目
     * @param orderId 查询区间订单号
     * @return
     */
    Integer findLimitBetween(Long start, Long end, Long orderId, Integer collectionId);

    /**
     * 成交趋势
     *
     * @param id
     * @return
     */
    TradingTrendVO tradingTrend(Long id);
    TradingTrendVO tradingTrendForConsensus(Long id);
    TradingTrendVO tradingTrendNotInConsensus(Long id);

    /**
     * 流转记录
     *
     * @param flowRecordDTO
     * @return
     */
    Page<FlowRecordVO> flowRecord(FlowRecordDTO flowRecordDTO);
    Page<FlowRecordVO> flowRecordForConsensus(FlowRecordDTO flowRecordDTO);
    Page<FlowRecordVO> flowRecordNotInConsensus(FlowRecordDTO flowRecordDTO);


    /**
     * 免费领取藏品
     *
     * @param userInfo
     * @param productId
     */
    void receiveFreeCollection(UserInfo userInfo, Long productId, Integer count);


    /**
     * 查询已完成首发订单数量
     * @param userId
     * @return
     */
    Integer orderCount(Long userId);
}
